package Formularios;

import BD.Funcionarios;
import BD.Validacao;

import BD.utilsPim;
import BD.utilsbd;
import java.sql.Date;

import java.util.ArrayList;
import javax.swing.JOptionPane;

public class FormFuncionarios extends javax.swing.JFrame {

    private boolean Incluindo;
    private int ponteiro = 0;
    private ArrayList<Funcionarios> listFuncionarios = new ArrayList<Funcionarios>();
    private Validacao vldc = new Validacao();
    utilsPim utlp = new utilsPim(); 
    utilsbd utlbd = new utilsbd();
    
    /**
     * Creates new form FormFuncionario
     */
    public FormFuncionarios() {
        initComponents();
        TravaBtns(false, true, false);
        setLocationRelativeTo(null);
        CarregaCombobox();
    }
    private void CarregaCombobox(){
        jcbxcargo.removeAllItems();        
        jcbxcargo.addItem("Garçom");
        jcbxcargo.addItem("Gerente");
        jcbxcargo.addItem("Entregador");
        jcbxcargo.addItem("Caixa");
        jcbxcargo.addItem("Pizzaiolo");
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dateComponentFormatter1 = new org.jdatepicker.impl.DateComponentFormatter();
        jLabel2 = new javax.swing.JLabel();
        jtcodigo = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtNome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jtrg = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jtclt = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jtsalario = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jtnomemae = new javax.swing.JTextField();
        Separador2 = new javax.swing.JSeparator();
        jpnlPesq = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtPesq = new javax.swing.JTextField();
        jbtnPesquisa = new javax.swing.JButton();
        jpNavegacao = new javax.swing.JPanel();
        jbtnFirst = new javax.swing.JButton();
        jbtnPrior = new javax.swing.JButton();
        jbtnNext = new javax.swing.JButton();
        jbtnLast = new javax.swing.JButton();
        Separador1 = new javax.swing.JSeparator();
        jbtncancelar = new javax.swing.JButton();
        jbtnexcluir = new javax.swing.JButton();
        jbtnGravar = new javax.swing.JButton();
        jbtnAlterar = new javax.swing.JButton();
        jbtnNovo = new javax.swing.JButton();
        jtdataadmissao = new com.toedter.calendar.JDateChooser();
        jtcpf = new javax.swing.JFormattedTextField();
        jcbxcargo = new javax.swing.JComboBox();
        jtdatanascimento = new com.toedter.calendar.JDateChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Master Pizza - Cadastro de Funcionários");

        jLabel2.setText("Codigo");

        jLabel3.setText("Nome");

        jtNome.setToolTipText("");
        jtNome.setName(""); // NOI18N
        jtNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtNomeActionPerformed(evt);
            }
        });
        jtNome.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtNomeKeyPressed(evt);
            }
        });

        jLabel4.setText("CPF");

        jLabel5.setText("RG");

        jtrg.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtrgKeyTyped(evt);
            }
        });

        jLabel6.setText("CLT");

        jtclt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtcltKeyTyped(evt);
            }
        });

        jLabel7.setText("Data de Nascimento");

        jLabel8.setText("Data de Admissão");

        jLabel9.setText("Salario");

        jtsalario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtsalarioActionPerformed(evt);
            }
        });
        jtsalario.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtsalarioKeyTyped(evt);
            }
        });

        jLabel10.setText("Cargo");

        jLabel11.setText("Nome da Mãe");

        jtnomemae.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtnomemaeActionPerformed(evt);
            }
        });

        jLabel1.setText("Descrição");

        jbtnPesquisa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Pesquisa.png"))); // NOI18N
        jbtnPesquisa.setText("Pesquisar");
        jbtnPesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnPesquisaActionPerformed(evt);
            }
        });

        jbtnFirst.setText("<<");
        jbtnFirst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnFirstActionPerformed(evt);
            }
        });

        jbtnPrior.setText("<");
        jbtnPrior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnPriorActionPerformed(evt);
            }
        });

        jbtnNext.setText(">");
        jbtnNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnNextActionPerformed(evt);
            }
        });

        jbtnLast.setText(">>");
        jbtnLast.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnLastActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpNavegacaoLayout = new javax.swing.GroupLayout(jpNavegacao);
        jpNavegacao.setLayout(jpNavegacaoLayout);
        jpNavegacaoLayout.setHorizontalGroup(
            jpNavegacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpNavegacaoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbtnFirst)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnPrior)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnNext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnLast)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jpNavegacaoLayout.setVerticalGroup(
            jpNavegacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpNavegacaoLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(jpNavegacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnFirst)
                    .addComponent(jbtnPrior)
                    .addComponent(jbtnNext)
                    .addComponent(jbtnLast)))
        );

        javax.swing.GroupLayout jpnlPesqLayout = new javax.swing.GroupLayout(jpnlPesq);
        jpnlPesq.setLayout(jpnlPesqLayout);
        jpnlPesqLayout.setHorizontalGroup(
            jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlPesqLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnlPesqLayout.createSequentialGroup()
                        .addComponent(jtPesq)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtnPesquisa))
                    .addGroup(jpnlPesqLayout.createSequentialGroup()
                        .addGap(54, 54, 54)
                        .addComponent(jpNavegacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addComponent(Separador1, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        jpnlPesqLayout.setVerticalGroup(
            jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlPesqLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jpnlPesqLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtPesq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnPesquisa))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpNavegacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addComponent(Separador1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jbtncancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Cancelar.png"))); // NOI18N
        jbtncancelar.setText("Cancelar");
        jbtncancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtncancelarActionPerformed(evt);
            }
        });

        jbtnexcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Excluir.png"))); // NOI18N
        jbtnexcluir.setText("Excluir");
        jbtnexcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnexcluirActionPerformed(evt);
            }
        });

        jbtnGravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Gravar.png"))); // NOI18N
        jbtnGravar.setText("Gravar");
        jbtnGravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnGravarActionPerformed(evt);
            }
        });

        jbtnAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Alterar.png"))); // NOI18N
        jbtnAlterar.setText("Alterar");
        jbtnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAlterarActionPerformed(evt);
            }
        });

        jbtnNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Incluir.png"))); // NOI18N
        jbtnNovo.setText("Novo");
        jbtnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnNovoActionPerformed(evt);
            }
        });

        try {
            jtcpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jcbxcargo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Garçom", "Gerente", "Entregador", "Caixa", "Pizzaiolo" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpnlPesq, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(Separador2)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtrg, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7))
                    .addComponent(jLabel2)
                    .addComponent(jtcodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jbtnNovo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtnAlterar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtnGravar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtnexcluir)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtncancelar))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jtnomemae, javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel3)
                                .addComponent(jtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jtsalario, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel9))
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel10)
                                        .addComponent(jcbxcargo, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(121, 121, 121)
                                    .addComponent(jtdatanascimento, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel6)
                                .addComponent(jtcpf, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel4)
                                .addComponent(jLabel8)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jtclt, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtdataadmissao, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jpnlPesq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addGap(12, 12, 12)
                .addComponent(jtcodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtcpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jtrg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtdatanascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtdataadmissao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcbxcargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtclt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtsalario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtnomemae, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(Separador2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtncancelar)
                    .addComponent(jbtnexcluir)
                    .addComponent(jbtnGravar)
                    .addComponent(jbtnAlterar)
                    .addComponent(jbtnNovo))
                .addGap(25, 25, 25))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnPesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnPesquisaActionPerformed
        Funcionarios func = new Funcionarios();
        func.setNome(jtPesq.getText());
        listFuncionarios = func.getItens();
        TravaBtns(false, true, true);
        jbtnFirstActionPerformed(evt);
    }//GEN-LAST:event_jbtnPesquisaActionPerformed

    private void TravaBtns(boolean incluindo, boolean navegando, boolean pesquisando) {
        jtcodigo.setEditable(false);
        jtNome.setEditable(incluindo);
        jtcpf.setEditable(incluindo);
        jtrg.setEditable(incluindo);
        jtclt.setEditable(incluindo);
        //jtdatanascimento.setEnabled(incluindo);
        //jtdataadmissao.setEnabled(incluindo);
        jtsalario.setEditable(incluindo);
        jcbxcargo.setEditable(incluindo);
        jtnomemae.setEditable(incluindo);
        jpNavegacao.setVisible(!incluindo);

        if (incluindo) {
            jbtncancelar.setVisible(true);
            jbtnGravar.setVisible(true);
            jpnlPesq.setVisible(false);
            jbtnexcluir.setVisible(false);
            jbtnNovo.setVisible(false);
            jbtnAlterar.setVisible(false);
        } else if (navegando) {
            jbtnAlterar.setVisible(true);
            jbtncancelar.setVisible(false);
            jbtnGravar.setVisible(false);
            jpnlPesq.setVisible(true);
            jbtnexcluir.setVisible(true);
            jbtnNovo.setVisible(true);
        }
        //jbtnPesquiza.enable(pTipo);
    }
    
    private boolean Validacao() {
                if(jtcpf.getText()== "   .   .   -  "){
                    vldc.Valida("", "CPF");
                    return false;
                }
        return (vldc.Valida(jtNome.getText(), "Nome")&&
                vldc.Valida(jtcpf.getText(), "CPF")  &&               
                vldc.Valida(jcbxcargo.getSelectedIndex()+1, "Cargo")  &&
                vldc.Valida(jtrg.getText(), "Rg")  &&
                vldc.Valida(jtclt.getText(), "CLT")  &&
                vldc.Valida(jtsalario.getText(), "Salário")  &&
                vldc.Valida(jtnomemae.getText(), "Mãe")  &&             
                vldc.Valida(jtdatanascimento, "Data Nacimento")&&
                vldc.Valida(jtdataadmissao, "Data Adimissão")&&
                vldc.ValidaV(jtsalario.getText(), "Salário"));
        
                
                //vldc.ValidaD(jtdatanascimento.getDate().toString(), "Data Nacimento");

    }

    private void limpaCampo() {
        this.jtcodigo.setText("");
        this.jtNome.setText("");
        this.jtcpf.setText("");
        this.jtrg.setText("");
        this.jtclt.setText("");
        this.jtdatanascimento.setDate(null);
        this.jtdataadmissao.setDate(null);
        this.jtsalario.setText("");
        this.jcbxcargo.setSelectedIndex(-1);
        this.jtnomemae.setText("");
        this.jtPesq.setText("");
    }
    
    private void movPonteiro(boolean first, boolean prior, boolean next, boolean last) {
        if (listFuncionarios.size() > 0) {
            if (first) {
                this.ponteiro = 0;
            } else if (prior) {
                this.ponteiro = this.ponteiro - 1;
                if (this.ponteiro < 0) {
                    this.ponteiro = 0;
                }
            } else if (next) {
                this.ponteiro = this.ponteiro + 1;
                if (this.ponteiro > (listFuncionarios.size() - 1)) {
                    this.ponteiro = (listFuncionarios.size() - 1);
                }
            } else if (last) {
                this.ponteiro = (listFuncionarios.size() - 1);
            }

            this.jtcodigo.setText(Integer.toString(listFuncionarios.get(this.ponteiro).getId_funcionarios()));
            this.jtNome.setText(listFuncionarios.get(this.ponteiro).getNome());
            this.jtcpf.setText(listFuncionarios.get(this.ponteiro).getCpf());
            this.jtrg.setText(listFuncionarios.get(this.ponteiro).getRg());
            this.jtclt.setText(listFuncionarios.get(this.ponteiro).getClt());
            this.jtdatanascimento.setDate(listFuncionarios.get(this.ponteiro).getDt_nascimento());
            this.jtdataadmissao.setDate(listFuncionarios.get(this.ponteiro).getDt_admissao());
            this.jtsalario.setText(utlp.formatavalor(listFuncionarios.get(this.ponteiro).getSalario()));
            this.jtnomemae.setText(listFuncionarios.get(this.ponteiro).getMae());
            
            this.jcbxcargo.removeAllItems();            
            this.jcbxcargo.addItem(listFuncionarios.get(this.ponteiro).getCargo());
            this.jcbxcargo.setSelectedIndex(0);
            
        } else {
            limpaCampo();
        }
    }
    
    private void jbtnFirstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnFirstActionPerformed
        movPonteiro(true, false, false, false);
    }//GEN-LAST:event_jbtnFirstActionPerformed

    private void jbtnPriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnPriorActionPerformed
        movPonteiro(false, true, false, false);
    }//GEN-LAST:event_jbtnPriorActionPerformed

    private void jbtnNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNextActionPerformed
        movPonteiro(false, false, true, false);
    }//GEN-LAST:event_jbtnNextActionPerformed

    private void jbtnLastActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnLastActionPerformed
        movPonteiro(false, false, false, true); 

    }//GEN-LAST:event_jbtnLastActionPerformed

    private void jbtncancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtncancelarActionPerformed
        Incluindo = false;
        TravaBtns(false, true, false);
        limpaCampo();
    }//GEN-LAST:event_jbtncancelarActionPerformed

    private void jbtnexcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnexcluirActionPerformed

        if (listFuncionarios.size() <= 0) {
            JOptionPane.showMessageDialog(null, "Nenhum registro Encontrado");
        } else {
            if (JOptionPane.showConfirmDialog(null, "Deseja exluir o Funcionário: " + jtNome.getText()) == 0) {
                if (listFuncionarios.get(ponteiro).excluir()) {
                    JOptionPane.showMessageDialog(null, "Operação bem sucedida");
                    limpaCampo();
                    jbtnPesquisaActionPerformed(evt);
                } else {
                    JOptionPane.showMessageDialog(null, "Erro ao excluir funcionário");
                }
            }
        }
    }//GEN-LAST:event_jbtnexcluirActionPerformed
    private void jbtnGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnGravarActionPerformed
        if (this.Validacao()) {
            Funcionarios func = new Funcionarios();

            func.setNome(this.jtNome.getText());
            func.setCpf(this.jtcpf.getText());
            func.setRg(this.jtrg.getText());
            func.setClt(this.jtclt.getText());
            func.setDt_nascimento(utlp.getDateChooserBDDT(this.jtdatanascimento));            
            func.setDt_admissao(utlp.getDateChooserBDDT(this.jtdataadmissao));
            func.setSalario(Float.parseFloat(this.jtsalario.getText()));
            func.setCargo(this.jcbxcargo.getSelectedItem().toString());
            func.setMae(this.jtnomemae.getText());

            if (Incluindo) {
                if (func.incluir()) {
                    TravaBtns(false, true, false);

                    jtPesq.setText(func.getNome());
                    jbtnPesquisaActionPerformed(evt);
                    jtPesq.setText("");
                    JOptionPane.showMessageDialog(null, "Funcionário Cadastro com Sucesso !");
                } else {
                    JOptionPane.showMessageDialog(null, "Erro ao Incluir Funcionário");
                }
            } else {
                func.setId_funcionarios(Integer.parseInt(this.jtcodigo.getText()));
                if (func.alterar()) {

                    jtPesq.setText(func.getNome());
                    jbtnPesquisaActionPerformed(evt);
                    jtPesq.setText("");

                    JOptionPane.showMessageDialog(null, "Funcionário Alterado com Sucesso !");
                } else {
                    JOptionPane.showMessageDialog(null, "Erro ao Alterar Funcionário");
                }
            }

        }
    }//GEN-LAST:event_jbtnGravarActionPerformed

    private void jbtnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAlterarActionPerformed
        if (listFuncionarios.size() > 0) {
            TravaBtns(true, false, false);
            Incluindo = false;
            String s = jcbxcargo.getSelectedItem().toString();            
            CarregaCombobox();
            utlp.getIndexComboboxSet(jcbxcargo, s);             
//            jtCusto.setText(utl.formatavalorsemmask(listProdutos.get(ponteiro).getCusto()));
            
            jtsalario.setText(utlp.formatavalorsemmask(listFuncionarios.get(ponteiro).getSalario()));
        } else {
            JOptionPane.showMessageDialog(null, "Nenhum registro Encontrado");
            
        }
    }//GEN-LAST:event_jbtnAlterarActionPerformed

    private void jbtnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNovoActionPerformed
        
        Incluindo = true;
        TravaBtns(true, false, false);
        limpaCampo();
        
        CarregaCombobox();
        jcbxcargo.setSelectedIndex(0);
    }//GEN-LAST:event_jbtnNovoActionPerformed

    private void jtcltKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtcltKeyTyped
        String caracteres = "0987654321";
        if (!caracteres.contains(evt.getKeyChar() + "")) {
            evt.consume();
        }
    }//GEN-LAST:event_jtcltKeyTyped

    private void jtNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtNomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtNomeActionPerformed

    private void jtsalarioKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtsalarioKeyTyped
        String caracteres = "0987654321.";
        if (!caracteres.contains(evt.getKeyChar() + "")) {
            evt.consume();
        }
    }//GEN-LAST:event_jtsalarioKeyTyped

    private void jtrgKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtrgKeyTyped
        String caracteres = "0987654321";
        if (!caracteres.contains(evt.getKeyChar() + "")) {
            evt.consume();
        }
    }//GEN-LAST:event_jtrgKeyTyped

    private void jtnomemaeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtnomemaeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtnomemaeActionPerformed

    private void jtsalarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtsalarioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtsalarioActionPerformed

    private void jtNomeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtNomeKeyPressed
        // TODO add your handling code here:
        utlp.MaxCaracter(jtNome, 35);
    }//GEN-LAST:event_jtNomeKeyPressed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormFuncionarios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormFuncionarios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormFuncionarios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormFuncionarios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormFuncionarios().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSeparator Separador1;
    private javax.swing.JSeparator Separador2;
    private org.jdatepicker.impl.DateComponentFormatter dateComponentFormatter1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JButton jbtnAlterar;
    private javax.swing.JButton jbtnFirst;
    private javax.swing.JButton jbtnGravar;
    private javax.swing.JButton jbtnLast;
    private javax.swing.JButton jbtnNext;
    private javax.swing.JButton jbtnNovo;
    private javax.swing.JButton jbtnPesquisa;
    private javax.swing.JButton jbtnPrior;
    private javax.swing.JButton jbtncancelar;
    private javax.swing.JButton jbtnexcluir;
    private javax.swing.JComboBox jcbxcargo;
    private javax.swing.JPanel jpNavegacao;
    private javax.swing.JPanel jpnlPesq;
    private javax.swing.JTextField jtNome;
    private javax.swing.JTextField jtPesq;
    private javax.swing.JTextField jtclt;
    private javax.swing.JTextField jtcodigo;
    private javax.swing.JFormattedTextField jtcpf;
    private com.toedter.calendar.JDateChooser jtdataadmissao;
    private com.toedter.calendar.JDateChooser jtdatanascimento;
    private javax.swing.JTextField jtnomemae;
    private javax.swing.JTextField jtrg;
    private javax.swing.JTextField jtsalario;
    // End of variables declaration//GEN-END:variables
}
